package com.hgd.tools;

import com.hgd.impl.SNMPSingle;

public class ThreadTest implements Runnable{
	private volatile Thread myThread;
    public void stopMyThread() {
        Thread tmpThread = myThread;
        myThread = null;
        if (tmpThread != null) {
            tmpThread.interrupt();
        }
    }
    public void run() {
        if (myThread == null) {
           return; // stopped before started.
        }
        try {
            // all the run() method's code goes here
            // do some work
            Thread.yield(); // let another thread have some time perhaps to stop this one.
            if (Thread.currentThread().isInterrupted()) {
               throw new InterruptedException("Stopped by ifInterruptedStop()");
            }
            // do some more work
        } catch (Throwable t) {
           // log/handle all errors here
        }
    }
    
    public static void main(String[] args) {
    	new Thread(new ThreadTest()).start();
	}
}    